package com.fly.show.casco;

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.Observable;
import java.util.Observer;
import java.util.Set;
import java.util.TreeSet;
import java.util.Vector;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;

/**
 * 
 * 全部组件可拖拽版本
 * 
 * @author 00fly
 * @version [版本号, 2020年5月2日]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
public class DMRT_Window_v1 implements Observer
{
    private Display display;
    
    private Shell shell;
    
    private Table tableA, tableB;
    
    Label stationCode, stationName, sysVersion, appVersion;
    
    private Text text_1, text_2, text_3, text_4, text_5, text_6, text_7, text_8, text_9;
    
    private Text text_10, text_11, text_12, text_13, text_14, text_15, text_16, text_17, text_18;
    
    private Text text_19, text_20, text_21, text_22, text_23, text_24, text_25, text_26, text_27;
    
    private Text text_28, text_29, text_30, text_31, text_32, text_33, text_34, text_35, text_36;
    
    private List infoLogList, warnLogList, errorLogList, debugLogList;
    
    public DMRT_Window_v1()
    {
        super();
        display = new Display();
        shell = new Shell(display, SWT.MIN | SWT.MAX | SWT.CLOSE | SWT.ON_TOP);
        shell.setText("DMRT 工具 V1.0");
        init(this);
        addMenu();
        addContent();
        
        InputStream is = this.getClass().getResourceAsStream("/img/icon.gif");
        if (is != null)
        {
            shell.setImage(new Image(display, is));
        }
        // 设置布局
        FillLayout shellLayout = new FillLayout();
        shellLayout.spacing = 8;
        shellLayout.marginWidth = 8;
        shellLayout.marginHeight = 8;
        shell.setLayout(shellLayout);
        shell.setSize(800, 600);
        
        // 设置默认居中
        Rectangle screeRec = display.getBounds();
        Rectangle shellRec = shell.getBounds();
        if (shellRec.height > screeRec.height)
        {
            shellRec.height = screeRec.height;
        }
        if (shellRec.width > screeRec.width)
        {
            shellRec.width = screeRec.width;
        }
        shell.setLocation((screeRec.width - shellRec.width) / 2, (screeRec.height - shellRec.height) / 2);
        shell.open();
        
        shell.addShellListener(new ShellAdapter()
        {
            @Override
            public void shellClosed(ShellEvent e)
            {
                MessageBox messagebox = new MessageBox(shell, SWT.ICON_QUESTION | SWT.YES | SWT.NO);
                messagebox.setText("确认退出");
                messagebox.setMessage("您确定要退出吗?");
                int message = messagebox.open();
                e.doit = (message == SWT.YES);
                if (message == SWT.YES)
                {
                    shell.dispose();
                    System.exit(0);
                }
            }
        });
        while (!shell.isDisposed())
        {
            if (!display.readAndDispatch())
            {
                display.sleep();
            }
        }
        display.dispose();
    }
    
    /**
     * 系统初始化
     * 
     * @see [类、类#方法、类#成员]
     */
    private void init(DMRT_Window_v1 mainWindow)
    {
        display.asyncExec(() -> {
            try
            {
                // 注册观察者
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
        });
    }
    
    /**
     * 初始化站点信息
     * 
     * @throws IOException
     * 
     * @see [类、类#方法、类#成员]
     */
    protected void initStation(Menu submenu)
    {
        try
        {
            Set<String> names = new TreeSet<String>();
            names.add("站点A");
            names.add("站点B");
            names.add("站点C");
            names.forEach(name -> new MenuItem(submenu, SWT.PUSH).setText(name));
        }
        catch (Exception e)
        {
            MessageDialog.openError(shell, "警告", "初始化站点数据失败!");
        }
    }
    
    /**
     * 添加菜单
     * 
     * @see [类、类#方法、类#成员]
     */
    private void addMenu()
    {
        Menu topMenu = new Menu(shell, SWT.BAR);
        MenuItem chooseItem = new MenuItem(topMenu, SWT.CASCADE);
        chooseItem.setText("切换(&S)");
        chooseItem.setAccelerator(SWT.CTRL + 'S');
        Menu submenu = new Menu(shell, SWT.DROP_DOWN);
        chooseItem.setMenu(submenu);
        initStation(submenu);
        
        MenuItem file = new MenuItem(topMenu, SWT.CASCADE);
        file.setText("文件(&F)");
        file.setAccelerator(SWT.CTRL + 'F');
        
        Menu filemenu = new Menu(shell, SWT.DROP_DOWN);
        file.setMenu(filemenu);
        MenuItem openLogMenuItem = new MenuItem(filemenu, SWT.CASCADE);
        openLogMenuItem.setText("查看日志(&O)");
        openLogMenuItem.setAccelerator(SWT.CTRL + 'O');
        openLogMenuItem.addSelectionListener(new SelectionAdapter()
        {
            @Override
            public void widgetSelected(SelectionEvent e)
            {
                try
                {
                    Desktop.getDesktop().open(new File("./Log"));
                }
                catch (Exception ex)
                {
                    MessageDialog.openError(shell, "错误", "查看日志文件失败!");
                }
            }
        });
        new MenuItem(filemenu, SWT.SEPARATOR);
        MenuItem exitMenuItem = new MenuItem(filemenu, SWT.PUSH);
        exitMenuItem.setText("退出(&X)");
        exitMenuItem.setAccelerator(SWT.CTRL + 'X');
        exitMenuItem.addSelectionListener(new SelectionAdapter()
        {
            @Override
            public void widgetSelected(SelectionEvent e)
            {
                MessageBox messagebox = new MessageBox(shell, SWT.ICON_QUESTION | SWT.YES | SWT.NO);
                messagebox.setText("确认退出");
                messagebox.setMessage("您确定要退出吗?");
                int message = messagebox.open();
                if (message == SWT.YES)
                {
                    shell.dispose();
                    System.exit(0);
                }
            }
        });
        
        MenuItem help = new MenuItem(topMenu, SWT.CASCADE);
        help.setText("帮助(&H)");
        help.setAccelerator(SWT.CTRL + 'H');
        Menu helpmenu = new Menu(shell, SWT.DROP_DOWN);
        help.setMenu(helpmenu);
        MenuItem useMenuItem = new MenuItem(helpmenu, SWT.PUSH);
        useMenuItem.setText("使用指南(&G)");
        useMenuItem.setAccelerator(SWT.CTRL + 'G');
        useMenuItem.addSelectionListener(new SelectionAdapter()
        {
            @Override
            public void widgetSelected(SelectionEvent event)
            {
                try
                {
                    Runtime.getRuntime().exec("hh .//config//dmrt_user.chm");
                }
                catch (Exception e)
                {
                    MessageDialog.openError(shell, "错误", "查看帮助文档失败!");
                }
            }
        });
        new MenuItem(helpmenu, SWT.SEPARATOR);
        MenuItem aboutMenuItem = new MenuItem(helpmenu, SWT.PUSH);
        aboutMenuItem.setText("查看版本(&V)");
        aboutMenuItem.addSelectionListener(new SelectionAdapter()
        {
            @Override
            public void widgetSelected(SelectionEvent event)
            {
                MessageDialog.openInformation(shell, "提示", "版本：V1.0\t\n代码标签：DMRT_V1.0");
            }
        });
        shell.setMenuBar(topMenu);
    }
    
    /**
     * 添加窗口内容
     * 
     * @see [类、类#方法、类#成员]
     */
    private void addContent()
    {
        SashForm topSashForm = new SashForm(shell, SWT.VERTICAL);
        creatBaseInfo(topSashForm);
        createAB(topSashForm);
        createComm(topSashForm);
        creatLog(topSashForm);
        topSashForm.setWeights(new int[] {1, 7, 3, 2});
    }
    
    private void creatBaseInfo(SashForm topSashForm)
    {
        Group infoGroup = new Group(topSashForm, SWT.NONE);
        FillLayout layout = new FillLayout(SWT.HORIZONTAL);
        layout.spacing = 2;
        layout.marginWidth = 2;
        layout.marginHeight = 2;
        infoGroup.setLayout(layout);
        infoGroup.setText("基本信息");
        
        stationCode = new Label(infoGroup, SWT.NONE);
        stationCode.setText("站点:");
        
        stationName = new Label(infoGroup, SWT.NONE);
        stationName.setText("站名:");
        
        sysVersion = new Label(infoGroup, SWT.NONE);
        sysVersion.setText("系统版本:");
        
        appVersion = new Label(infoGroup, SWT.NONE);
        appVersion.setText("应用版本：");
    }
    
    private void createAB(SashForm topSashForm)
    {
        SashForm mainSashForm = new SashForm(topSashForm, SWT.NONE);
        mainSashForm.setEnabled(false);
        Group aGroup = new Group(mainSashForm, SWT.NONE);
        aGroup.setLayout(new GridLayout(3, false));
        aGroup.setText("A系");
        
        // row1
        Label lblNewLabel = new Label(aGroup, SWT.NONE);
        lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
        lblNewLabel.setText("板卡信息");
        text_1 = new Text(aGroup, SWT.BORDER);
        text_1.setText("MPU1-A");
        text_1.setEditable(false);
        text_1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        
        text_2 = new Text(aGroup, SWT.BORDER);
        text_2.setText("MPU2-A");
        text_2.setEditable(false);
        text_2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        
        // row2
        Label lblNewLabel_1 = new Label(aGroup, SWT.NONE);
        lblNewLabel_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
        lblNewLabel_1.setText("运行状态");
        
        text_3 = new Text(aGroup, SWT.BORDER);
        text_3.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        text_4 = new Text(aGroup, SWT.BORDER);
        text_4.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        
        // row3
        Label lblNewLabel_2 = new Label(aGroup, SWT.NONE);
        lblNewLabel_2.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
        lblNewLabel_2.setText("角色状态");
        
        text_5 = new Text(aGroup, SWT.BORDER);
        text_5.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        text_6 = new Text(aGroup, SWT.BORDER);
        text_6.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        
        // row4
        Label lblNewLabel_3 = new Label(aGroup, SWT.NONE);
        lblNewLabel_3.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
        lblNewLabel_3.setText("同步状态");
        
        text_7 = new Text(aGroup, SWT.BORDER);
        text_7.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        text_8 = new Text(aGroup, SWT.BORDER);
        text_8.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        
        // row5
        Label lblNewLabel_4 = new Label(aGroup, SWT.NONE);
        lblNewLabel_4.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
        lblNewLabel_4.setText("周期号");
        text_9 = new Text(aGroup, SWT.BORDER);
        text_9.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        text_10 = new Text(aGroup, SWT.BORDER);
        text_10.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        
        // row6
        Label lblNewLabel_9 = new Label(aGroup, SWT.NONE);
        lblNewLabel_9.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
        lblNewLabel_9.setText("运行时间");
        text_11 = new Text(aGroup, SWT.BORDER);
        text_11.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        text_12 = new Text(aGroup, SWT.BORDER);
        text_12.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        
        // row7
        Label lblNewLabel_5 = new Label(aGroup, SWT.NONE);
        lblNewLabel_5.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
        lblNewLabel_5.setText("板卡温度");
        text_13 = new Text(aGroup, SWT.BORDER);
        text_13.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        
        text_14 = new Text(aGroup, SWT.BORDER);
        text_14.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        
        // row8
        Label lblNewLabel_6 = new Label(aGroup, SWT.NONE);
        lblNewLabel_6.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
        lblNewLabel_6.setText("看门狗状态");
        text_15 = new Text(aGroup, SWT.BORDER);
        text_15.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        text_16 = new Text(aGroup, SWT.BORDER);
        text_16.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        
        // row9
        Label lblNewLabel_7 = new Label(aGroup, SWT.NONE);
        lblNewLabel_7.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
        lblNewLabel_7.setText("宕机是否可重启");
        
        text_17 = new Text(aGroup, SWT.BORDER);
        text_17.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        text_18 = new Text(aGroup, SWT.BORDER);
        text_18.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        
        Group bGroup = new Group(mainSashForm, SWT.NONE);
        bGroup.setLayout(new GridLayout(3, false));
        bGroup.setText("B系");
        
        // row1
        Label lblNewLabel_8 = new Label(bGroup, SWT.NONE);
        lblNewLabel_8.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
        lblNewLabel_8.setText("板卡信息");
        
        text_19 = new Text(bGroup, SWT.BORDER);
        text_19.setText("MPU1-B");
        text_19.setEditable(false);
        text_19.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        text_20 = new Text(bGroup, SWT.BORDER);
        text_20.setText("MPU2-B");
        text_20.setEditable(false);
        text_20.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        
        // row2
        Label lblNewLabel_10 = new Label(bGroup, SWT.NONE);
        lblNewLabel_10.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
        lblNewLabel_10.setText("运行状态");
        text_21 = new Text(bGroup, SWT.BORDER);
        text_21.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        text_22 = new Text(bGroup, SWT.BORDER);
        text_22.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        
        // row3
        Label lblNewLabel_11 = new Label(bGroup, SWT.NONE);
        lblNewLabel_11.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
        lblNewLabel_11.setText("角色状态");
        
        text_23 = new Text(bGroup, SWT.BORDER);
        text_23.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        text_24 = new Text(bGroup, SWT.BORDER);
        text_24.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        
        // row4
        Label lblNewLabel_12 = new Label(bGroup, SWT.NONE);
        lblNewLabel_12.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
        lblNewLabel_12.setText("同步状态");
        text_25 = new Text(bGroup, SWT.BORDER);
        text_25.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        text_26 = new Text(bGroup, SWT.BORDER);
        text_26.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        
        // row5
        Label lblNewLabel_13 = new Label(bGroup, SWT.NONE);
        lblNewLabel_13.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
        lblNewLabel_13.setText("周期号");
        text_27 = new Text(bGroup, SWT.BORDER);
        text_27.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        text_28 = new Text(bGroup, SWT.BORDER);
        text_28.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        
        // row6
        Label lblNewLabel_14 = new Label(bGroup, SWT.NONE);
        lblNewLabel_14.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
        lblNewLabel_14.setText("运行时间");
        text_29 = new Text(bGroup, SWT.BORDER);
        text_29.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        text_30 = new Text(bGroup, SWT.BORDER);
        text_30.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        
        // row7
        Label lblNewLabel_15 = new Label(bGroup, SWT.NONE);
        lblNewLabel_15.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
        lblNewLabel_15.setText("板卡温度");
        text_31 = new Text(bGroup, SWT.BORDER);
        text_31.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        text_32 = new Text(bGroup, SWT.BORDER);
        text_32.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        
        // row8
        Label lblNewLabel_16 = new Label(bGroup, SWT.NONE);
        lblNewLabel_16.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
        lblNewLabel_16.setText("看门狗状态");
        text_33 = new Text(bGroup, SWT.BORDER);
        text_33.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        text_34 = new Text(bGroup, SWT.BORDER);
        text_34.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        
        // row9
        Label lblNewLabel_17 = new Label(bGroup, SWT.NONE);
        lblNewLabel_17.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
        lblNewLabel_17.setText("宕机是否可重启");
        text_35 = new Text(bGroup, SWT.BORDER);
        text_35.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        text_36 = new Text(bGroup, SWT.BORDER);
        text_36.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    }
    
    /**
     * 展示通信版信息
     * 
     * @param topSashForm
     * @see [类、类#方法、类#成员]
     */
    private void createComm(SashForm topSashForm)
    {
        SashForm downSashForm = new SashForm(topSashForm, SWT.NONE);
        downSashForm.setEnabled(false);
        Group leftGroup = new Group(downSashForm, SWT.NONE);
        leftGroup.setText("通信A");
        leftGroup.setLayout(new GridLayout(1, true));
        
        // 表格
        tableA = new Table(leftGroup, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.HIDE_SELECTION);
        tableA.setLinesVisible(true);
        tableA.setHeaderVisible(true);
        tableA.setLayoutData(new GridData(GridData.FILL_BOTH));
        String[] columnHeaders = {"通信版名-A", "网口1", "网口2", "网口3", "网口4"};
        Arrays.asList(columnHeaders).forEach(head -> {
            TableColumn column = new TableColumn(tableA, SWT.NONE);
            column.setText(head);
            column.setWidth(100);
        });
        
        Group rightGroup = new Group(downSashForm, SWT.NONE);
        rightGroup.setText("通信B");
        rightGroup.setLayout(new GridLayout(1, true));
        
        // 表格
        tableB = new Table(rightGroup, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.HIDE_SELECTION);
        tableB.setLinesVisible(true);
        tableB.setHeaderVisible(true);
        tableB.setLayoutData(new GridData(GridData.FILL_BOTH));
        String[] columnHeadersB = {"通信版名-B", "网口1", "网口2", "网口3", "网口4"};
        Arrays.asList(columnHeadersB).forEach(head -> {
            TableColumn column = new TableColumn(tableB, SWT.NONE);
            column.setText(head);
            column.setWidth(100);
        });
    }
    
    private void creatLog(SashForm topSashForm)
    {
        TabFolder tabFolder = new TabFolder(topSashForm, SWT.NONE);
        TabItem one = new TabItem(tabFolder, SWT.NONE);
        one.setText("信息");
        one.setControl(getInfoControl(tabFolder));
        
        TabItem two = new TabItem(tabFolder, SWT.NONE);
        two.setText("警告");
        two.setControl(getWarnControl(tabFolder));
        
        TabItem three = new TabItem(tabFolder, SWT.NONE);
        three.setText("错误");
        three.setControl(getErrorControl(tabFolder));
        
        TabItem four = new TabItem(tabFolder, SWT.NONE);
        four.setText("调试");
        four.setControl(getDebugControl(tabFolder));
    }
    
    private Control getInfoControl(TabFolder tabFolder)
    {
        infoLogList = new List(tabFolder, SWT.BORDER | SWT.SINGLE | SWT.WRAP);
        infoLogList.setItems(new String[] {"DMRT平台运行中"});
        return infoLogList;
    }
    
    private Control getWarnControl(TabFolder tabFolder)
    {
        warnLogList = new List(tabFolder, SWT.BORDER | SWT.SINGLE | SWT.WRAP);
        return warnLogList;
    }
    
    private Control getErrorControl(TabFolder tabFolder)
    {
        errorLogList = new List(tabFolder, SWT.BORDER | SWT.SINGLE | SWT.WRAP);
        return errorLogList;
    }
    
    private Control getDebugControl(TabFolder tabFolder)
    {
        debugLogList = new List(tabFolder, SWT.BORDER | SWT.SINGLE | SWT.WRAP);
        return debugLogList;
    }
    
    /**
     * 接受到消息显示处理
     * 
     * @param observable
     * @param objMsg
     */
    @Override
    @SuppressWarnings("unchecked")
    public void update(Observable observable, Object objMsg)
    {
        if (objMsg instanceof Map)
        {
            Map<String, String> map = (Map<String, String>)objMsg;
            for (String key : map.keySet())
            {
                String msg = (String)map.get(key);
                switch (key)
                {
                    case "start":
                        String[] items = infoLogList.getItems();
                        Vector<String> vector = new Vector<String>(Arrays.asList(items));
                        vector.add(msg);
                        infoLogList.setItems(vector.toArray(new String[0]));
                        break;
                    case "stationCode":
                        stationCode.setText("站点：" + msg);
                        break;
                    case "stationName":
                        stationName.setText("站名：" + msg);
                        break;
                    case "sysVersion":
                        sysVersion.setText("系统版本：" + msg);
                        break;
                    case "appVersion":
                        appVersion.setText("应用版本：" + msg);
                        break;
                    default:
                        break;
                }
            }
        }
    }
    
    public static void main(String[] args)
    {
        new DMRT_Window_v1();
    }
}
